package com.hzjq.core.cmd

import android.text.TextUtils
import com.hzjq.core.checker.OnErrorStateCheckCallback

class Cmd {

    var keyOk: String
    var keyError: String
    var cmd: String
    var key: Key? = null
    var minAckLength = 0
    var checker: OnErrorStateCheckCallback? = null


    constructor(keyOk: String, keyError: String, cmd: String) {
        this.keyOk = keyOk
        this.keyError = keyError
        this.cmd = cmd
    }

    constructor(keyOk: String, keyError: String, cmd: String, checker: OnErrorStateCheckCallback) {
        this.keyOk = keyOk
        this.keyError = keyError
        this.cmd = cmd
        this.checker = checker
    }

    constructor(keyOk: String, keyError: String, cmd: String, minAckLength: Int) {
        this.keyOk = keyOk
        this.keyError = keyError
        this.cmd = cmd
        this.minAckLength = minAckLength
    }

    constructor(
        keyOk: String,
        keyError: String,
        cmd: String,
        minAckLength: Int,
        checker: OnErrorStateCheckCallback
    ) {
        this.keyOk = keyOk
        this.keyError = keyError
        this.cmd = cmd
        this.minAckLength = minAckLength
        this.checker = checker
    }


    class Key {
        var start = ""
        var key = ""
        var startIndex = 0
        var endIndex = 0

        constructor(start: String, key: String, startIndex: Int, endIndex: Int) {
            this.start = start
            this.key = key
            this.startIndex = startIndex
            this.endIndex = endIndex
        }
    }

    override fun equals(other: Any?): Boolean {
        if (other is Cmd) {
//            if (TextUtils.isEmpty(other.keyOk) && !TextUtils.isEmpty(keyOk)) {
//                return false
//            }
//            if (!TextUtils.isEmpty(other.keyOk) && TextUtils.isEmpty(keyOk)) {
//                return false
//            }
//            if (!TextUtils.isEmpty(other.keyOk) && !TextUtils.isEmpty(keyOk) && !TextUtils.equals(
//                    other.keyOk,
//                    keyOk
//                )
//            ) {
//                return false
//            }
//            if (TextUtils.isEmpty(other.keyError) && !TextUtils.isEmpty(keyError)) {
//                return false
//            }
//            if (!TextUtils.isEmpty(other.keyError) && TextUtils.isEmpty(keyError)) {
//                return false
//            }
//            if (!TextUtils.isEmpty(other.keyError) && !TextUtils.isEmpty(keyError) && !TextUtils.equals(
//                    other.keyError,
//                    keyError
//                )
//            ) {
//                return false
//            }
//            if (other.key == null && key != null) {
//                return false
//            }
//            if (other.key != null && key == null) {
//                return false
//            }
//            if(other.key != null && key != null) {
//                if (!TextUtils.equals(other.key!!.key, key!!.key)) {
//                    return false
//                }
//                if (TextUtils.equals(other.key!!.start, key!!.start)) {
//                    return false
//                }
//                if (other.key!!.endIndex != key!!.endIndex) {
//                    return false
//                }
//                if (other.key!!.startIndex != key!!.startIndex) {
//                    return false
//                }
//            }
            return TextUtils.equals(other.cmd, cmd)
        }
        return super.equals(other)
    }
}